www.gusucode.com > VC++ 模拟超市POS机-源码程序 > VC++ 模拟超市POS机-源码程序/code/POS机/Product.cpp

    //Download by http://www.NewXing.com
// Product.cpp: implementation of the Product class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Product.h"
#include <string.h>
#include <stdio.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Product::Product()
{
//	id = NULL;
//	name = NULL;
//	div = NULL;
}

Product::Product(char* pid, char *pname, float pprice, char *pdiv, int pmount)
{
//	id = new char[strlen(pid)+1];
//    name = new char[strlen(pname)+1];
//    div = new char[strlen(pdiv)+1];

    strcpy(id, pid);
    strcpy(name,pname);
    strcpy(div, pdiv);

    price = pprice;
    mount = pmount;
    total = price * mount;
}

Product::~Product()
{
   // if(id!=NULL)delete [] id;
    //if(name!=NULL)delete [] name;
    //if(div!=NULL)delete [] div;
}

char* Product::getId()
{
    return id;
}

void Product::setId(char* pid)
{
//    if(id!=NULL)delete [] id;
//    id = new char[strlen(pid)+1];
    strcpy(id, pid);
}

char* Product::getName()
{
    return name;
}

void Product::setName(char* pname)
{
  //  if(name!=NULL)delete [] name;
   // name = new char[strlen(pname)+1];
    strcpy(name, pname);
}

char* Product::getDiv()
{
    return div;
}

void Product::setDiv(char* pdiv)
{
    //if(div!=NULL)delete [] div;
    //div = new char[strlen(pdiv)+1];
    strcpy(div, pdiv);
}

float Product::getPrice()
{
    return price;
}

void Product::setPrice(float pprice)
{
    price = pprice;
}

int Product::getMount()
{
    return mount;
}

void Product::setMount(int pmount)
{
    mount = pmount;
}


void Product::updateTotal()
{
    total = price * mount;
}

void Product::display()
{
    printf("%-10s%-10s%-5f%5s    %-5d%-8f\n",id,name,price,div,mount,total);
}